package com.hugboy.stringbuilder;
/*
stringbuilder 相比 string 有更高的效率
 */
public class Demo1stringbuilder {
    public static void main(String[] args) {
        // use String
        stringCase();
        // use stringbuilder
        long startTime = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=50000; i++){
            sb.append(i);
        }
        long endTime = System.currentTimeMillis();

        System.out.println(sb);
        System.out.println("TIME:");
        System.out.println(endTime - startTime);

    }

    private static void stringCase() {
        long startTime = System.currentTimeMillis();  // 1979~now

        System.out.println(startTime);

        String s = "";
        for(int i=1; i<=50000; i++){
            s+=i;
        }
        System.out.println(s);

        long endTime = System.currentTimeMillis();
        System.out.println("TIME:\n");
        System.out.println(endTime-startTime);  // 6064
    }
}
